package com.sxyjhh.fg_data_push.service;

//import com.sxyjhh.fg_data_push.utils.redis.RedisOperator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisCluster;

import java.sql.SQLException;
import java.util.Date;
import java.util.Set;

/**
 * Created by Administrator on 2018/6/29.
 */

@Component
public class ScheduleTask {

    private static Logger log = LoggerFactory.getLogger(ScheduleTask.class);

    /*@Autowired
    private RedisOperator redisOperator;*/

   /* @Autowired
    private JedisCluster jedisCluster;*/

    @Autowired
    private PushDataManager pushDataManager;

/*    //二级结构师
   // @Scheduled(cron = "0 40 10 * * ?")
    public void structuralTask() throws SQLException {
        Date sTime = new Date();
        log.info("==========TWO STRUCTURAL TASK RUN===========");

        int i = delRedisData("STRUCTURAL");
        log.info("===========DELETE REDIS DATA===========");
        log.info("REDIS NUM： " + i);

        dataExchangeService.startSynData();
        log.info("TWO STRUCTURAL TASK END");

        log.info("==========TASK TIME==========");
        long endTime = new Date().getTime() - sTime.getTime();
        log.info((endTime/ 1000) + "S");

    }

    //二级建造师
  //  @Scheduled(cron = "0 0 11 * * ?")
    public void chartProScheduleTask() throws SQLException {
        Date sTime = new Date();
        log.info("==========TWO BUILDER TASK RUN===========");
        dataExchangeService.startSynData2();
        log.info("TWO BUILDER TASK END");

        log.info("==========TASK TIME==========");
        long endTime = new Date().getTime() - sTime.getTime();
        log.info((endTime/ 1000) + "S");
    }


    //项目经理违法违规
    @Scheduled(cron = "0 0 9 * * ?")
    public void chartYthJlTask() throws SQLException {
        Date sTime = new Date();
        log.info("==========chartYthJlTask RUN===========");
        creditInquiryService.dealCreditInfo("yth_jl");
        log.info("chartYthJlTask END");

        log.info("==========TASK TIME==========");
        long endTime = new Date().getTime() - sTime.getTime();
        log.info((endTime/ 1000) + "S");
    }
    //企业信用
    @Scheduled(cron = "0 30 9 * * ?")
    public void chartYthQyTask() throws SQLException {
        Date sTime = new Date();
        log.info("==========chartYthQyTask RUN===========");
        creditInquiryService.dealCreditInfo("yth_qy");
        log.info("chartYthQyTask END");

        log.info("==========TASK TIME==========");
        long endTime = new Date().getTime() - sTime.getTime();
        log.info((endTime/ 1000) + "S");
    }*/


    //双公示 许可信息
    @Scheduled(cron = "0 10 6 * * 1")
    public void chartYjlXkxxTask() throws SQLException {
        Date sTime = new Date();
        log.info("==========chartYjlXkxxTask RUN===========");
        try {
            pushDataManager.pushCreditData();
        } catch (Exception e) {
            e.printStackTrace();
        }
        log.info("chartYjlXkxxTask END");

        log.info("==========TASK TIME==========");
        long endTime = new Date().getTime() - sTime.getTime();
        log.info((endTime/ 1000) + "S");
    }

/*    //删除信息
    public int delRedisData(String tabName) {
        //删除记录
        Set<String> set = redisOperator.keys(tabName + "*");
        int i = 0;
        if (set != null && set.size() > 0) {
            for (String redisKey : set) {
                i += jedisCluster.del(redisKey);
            }
        }
        return i;
    }*/
}
